package yyy.ab.common.core;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 响应数据对象
 */
public class ResultBean {

    /**
     * 响应状态码
     */
    private String code = "";
    /**
     * 响应信息
     */
    private String msg = "";
    /**
     * 响应时间
     */
    private String resptime = String.valueOf(new Date().getTime());
    /**
     * 响应数据
     */
    private Object data = new HashMap<Map, Object>();
    /**
     * 响应是否成功
     */
    private boolean success;

    public ResultBean() {
    }

    public ResultBean(String code) {
        this.code = code;
        this.msg = ResultCode.getMsg(code);
    }

    public ResultBean(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultBean(String code, String msg, Object data) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }


    public static ResultBean error(String code) {
        return new ResultBean(code, ResultCode.getMsg(code));
    }


    public static ResultBean errorMsg(String msg) {
        return new ResultBean(ResultCode.RESULT_STATUS_ERROR, msg);
    }

    public static ResultBean errorMsg(String code, String msg) {
        return new ResultBean(code, msg);
    }

    public static ResultBean success() {
        return new ResultBean(ResultCode.RESULT_STATUS_SUCCESS, ResultCode.getMsg(ResultCode.RESULT_STATUS_SUCCESS));
    }

    public static ResultBean success(String msg) {
        return new ResultBean(ResultCode.RESULT_STATUS_SUCCESS, msg);
    }

    public static ResultBean success(String msg, Object data) {
        return new ResultBean(ResultCode.RESULT_STATUS_SUCCESS, msg, data);
    }

    public static ResultBean success(Object data) {
        return new ResultBean(ResultCode.RESULT_STATUS_SUCCESS, ResultCode.getMsg(ResultCode.RESULT_STATUS_SUCCESS), data);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getResptime() {
        return resptime;
    }

    public void setResptime(String resptime) {
        this.resptime = resptime;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public boolean getSuccess() {
        return ResultCode.RESULT_STATUS_SUCCESS.equals(this.code);
    }
}
